package com.leetcode.LC_MED;

import java.util.Arrays;
import java.util.HashSet;

public class LC720 {
    public String longestWord(String[] words) {

        Arrays.sort(words);
        HashSet<String> set = new HashSet<>();
        String rs="";
        for (String word : words) {
            if (word.length()==1||set.contains(word.substring(0,word.length()-1))){
                rs=word.length()>rs.length()?word:rs;
                set.add(word);
            }
        }

        return rs;

    }
}
